

import 'package:flutter/material.dart';
import 'package:huajianshe_app/widget/RoundedCornerWidget.dart';

class DialogUtil {
  static void showBottomDialogV2(BuildContext context, Widget child, {double? height, double radius = 0, cornerPosition = CornerPosition.ALL,
    EdgeInsetsGeometry? margin = EdgeInsets.zero, Color bgColor = Colors.white}) {
    if (height != null) {
      if (height > 0 && height <= 1) {
        height = MediaQuery.of(context).size.height * height;
      }
    }
    showModalBottomSheet(
      shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(cornerPosition & CornerPosition.LT == CornerPosition.LT ? radius : 0),
            topRight: Radius.circular(cornerPosition & CornerPosition.RT == CornerPosition.RT ? radius : 0),
            bottomRight: Radius.circular(cornerPosition & CornerPosition.RB == CornerPosition.RB ? radius : 0),
            bottomLeft: Radius.circular(cornerPosition & CornerPosition.LB == CornerPosition.LB ? radius : 0),
          )
      ),
      backgroundColor: bgColor,
      builder: (BuildContext context) {
        return Container(
            margin: margin,
            height: height,
            child: child //如果需要圆角，child的background需要设置为transparent
        );
      },
      context: context,
      isScrollControlled: true,
    );
  }

  static void showBottomDialog(BuildContext context, Widget child, {double? height, double radius = 0, cornerPosition = CornerPosition.ALL,
    EdgeInsetsGeometry? margin = EdgeInsets.zero, Color bgColor = Colors.white}) {
    if (height != null) {
      if (height > 0 && height <= 1) {
        height = MediaQuery.of(context).size.height * height;
      }
    }
    showModalBottomSheet(
      context: context,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      builder: (context) => Container(
          margin: margin,
          height: height,
          decoration: new BoxDecoration(
            color: bgColor,
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(cornerPosition & CornerPosition.LT == CornerPosition.LT ? radius : 0),
              topRight: Radius.circular(cornerPosition & CornerPosition.RT == CornerPosition.RT ? radius : 0),
              bottomRight: Radius.circular(cornerPosition & CornerPosition.RB == CornerPosition.RB ? radius : 0),
              bottomLeft: Radius.circular(cornerPosition & CornerPosition.LB == CornerPosition.LB ? radius : 0),
            ),
          ),
          child: child
      ),
    );
  }
}